<template>
  <div>
    <TopNav title="我的关注" />
    <div class="list">
      <!-- 列表： -->
      <div class="item" v-for="user in followList" :key="user.id">
        <img
          v-if="user.head_img"
          :src="$axios.defaults.baseURL + user.head_img"
          alt=""
          class="avatar"
        />
        <img v-else src="../../assets/logo1.jpg" alt="" class="avatar" />
        <div class="info">
          <div class="name">{{ user.nickname }}</div>
          <div class="date">2020-12-12</div>
        </div>
        <div class="cancelBtn" @click="unFollow(user.id)">取消关注</div>
      </div>
    </div>
  </div>
</template>

<script>
import TopNav from "../../components/TopNav";
export default {
  components: {
    TopNav,
  },
  data() {
    return {
      // 创建一个空数组：
      followList: [],
    };
  },
  created() {
    // 页面一进来就需要拿数据：
    this.loadPage();
  },
  methods: {
    loadPage() {
      this.$axios({
        url: "/user_follows",
      }).then((res) => {
        console.log(res.data);
        const { data } = res.data;
        this.followList = data;
      });
    },
    // 取消
    unFollow(userId) {
      this.$axios({
        url: "/user_unfollow/" + userId,
      }).then((res) => {
        console.log(res.data);
        this.loadPage();
      });
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  display: flex;
  padding: 20 / 360 * 100vw;
  border-bottom: 1px solid #dddd;
  align-items: center;
  .avatar {
    width: 40 / 360 * 100vw;
    height: 40 / 360 * 100vw;
    border-radius: 50%;
    object-fit: cover;
  }
  .info {
    flex-grow: 1;
    padding-left: 10 / 360 * 100vw;
    .name {
      font-size: 16 / 360 * 100vw;
      color: #515151;
    }
    .date {
      font-size: 14 / 360 * 100vw;
      color: #8d8d8d;
      padding-top: 4 / 360 * 100vw;
    }
  }
  .cancelBtn {
    line-height: 38 / 360 * 100vw;
    line-height: 38 / 360 * 100vw;
    font-size: 12 / 360 * 100vw;
    padding: 0 16 / 360 * 100vw;
    color: #333;
    // text-align: center;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 19 / 360 * 100vw;
  }
}
</style>